package leetcode.editor.cn;

import java.util.Arrays;

//[455]分发饼干
public class AssignCookies455{
public static void main(String[] args) {
   Solution solution = new AssignCookies455().new Solution();
   
}

  //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    //执行耗时:8 ms,击败了24.64% 的Java用户
    public int findContentChildren(int[] g, int[] s) {
        if (g == null || g.length < 1) return 0;
        if (s == null || s.length < 1) return 0;

        int res = 0;
        Arrays.sort(g);
        Arrays.sort(s);

        int lenChild = g.length;
        int lenS = s.length;
        int indexC = 0;
        int indexS = 0;
        while (indexC < lenChild && indexS < lenS){
            if (s[indexS] >= g[indexC]){
                res++;
                indexC++;
                indexS++;
            }else {
                indexS++;
            }
        }
        return res;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}